package com.liux.controller;


import org.apache.catalina.Session;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @RequestMapping("/user/login")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password,
                        Model model, HttpSession session){

        if(!StringUtils.isEmpty(username) && "123456".equals(password)){
            System.out.println("----进来了-------"+username);
            //添加Session
            session.setAttribute("loginUser",username);
            return "redirect:/main.html";
        }else{
            System.out.println("----并没有进来了-------"+username);
            model.addAttribute("msg","账号或者密码错误");
            return "index";
        }
    }
    @RequestMapping("/user/logout")
    public String logout( HttpSession session){
        session.invalidate();
        return "redirect:/index.html";
    }
}
